package com.gorkr.labuladong.data_struct.array;

import org.junit.jupiter.api.Test;

/**
 * @author gorkr
 * @date 2022/06/03 09:57
 **/
public class E26RemoveDuplicatesFromSortedArray {
    public int removeDuplicates(int[] nums) {
        // 快慢指针
        int low = 0, fast = 1;
        // todo: 数组长度为0和1的情况
        if(nums.length<=1){
            return nums.length;
        }
        // 边界问题
        while(fast< nums.length){
            if(nums[low]==nums[fast]){
                fast++;
            }else {
                nums[++low] = nums[fast];
                fast++;
            }
        }


        return low+1;
    }

    @Test
    public void test(){
        int[] nums = {0,0,1,1,1,2,2,3,3,4};
        System.out.println(removeDuplicates(nums));
    }

}
    